/**
 * Copyright &copy; 2012-2016 <a href="https://www.kaaction.com">KAA</a> All rights reserved All rights reserved.
 */
package com.kaaction.modules.mer.service;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.google.common.collect.Lists;
import com.kaaction.common.persistence.Page;
import com.kaaction.common.service.CrudService;
import com.kaaction.modules.mer.dao.OperationProductDao;
import com.kaaction.modules.mer.dao.OperationProductDetailDao;
import com.kaaction.modules.mer.entity.OperationProduct;

/**
 * 商品运营Service
 * @author huanghaiming
 * @version 2017-07-06
 */
@Service
@Transactional(readOnly = true)
public class OperationProductService extends CrudService<OperationProductDao, OperationProduct> {

	@Autowired
	OperationProductDetailDao operationProductDetailDao;
	
	public OperationProduct get(String id) {
		return super.get(id);
	}
	
	public List<OperationProduct> findList(OperationProduct operationProduct) {
		return super.findList(operationProduct);
	}
	
	public Page<OperationProduct> findPage(Page<OperationProduct> page, OperationProduct operationProduct) {
		return super.findPage(page, operationProduct);
	}
	
	@Transactional(readOnly = false)
	public void save(OperationProduct operationProduct) {
		super.save(operationProduct);
	}
	
	@Transactional(readOnly = false)
	public void delete(OperationProduct operationProduct) {
		super.delete(operationProduct);
	}

	@Transactional(readOnly = false)
	public void updateIsShow(OperationProduct operationProduct) {
		super.dao.updateIsShow(operationProduct);
	}

	public List<Map<String,Object>> selOperProduct() {
		
		List<Map<String,Object>> listMap = Lists.newArrayList();
		
		List<Map<String,Object>> listOperPro= super.dao.selOperProduct();
		
		if(listOperPro.size()>0){
			
			for(Map<String,Object> mapOperPro:listOperPro){
				
				String id = (String) mapOperPro.get("id");
				if(StringUtils.isNotBlank(id)){
					mapOperPro.put("listProduct",operationProductDetailDao.selOperProductDtl(id));
					listMap.add(mapOperPro);
				}
			}
		}
		
		return  listMap;
	}

	public Map<String,Object> selOperProductDtl(String id) {
		
		Map<String,Object> map = super.dao.selOperPro(id);
		if(map!=null&&map.size()>0){
			map.put("listProduct",operationProductDetailDao.selOperProductDtl((String)map.get("id")));
		}
		return map;
	}
	
}